import {
  Column,
  CreateDateColumn,
  Entity,
  JoinTable,
  ManyToMany,
  ManyToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { User } from './user.entity';
import { Tags } from './tags.entity';
import { Exclude } from 'class-transformer';

@Entity()
export class Article {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ unique: true })
  title: string;

  @Column({ type: 'text' })
  content: string;

  @Column()
  imgUrl: string;

  @Column()
  desc: string;

  @CreateDateColumn()
  createTime: Date;

  @UpdateDateColumn()
  updateTime: Date;

  @ManyToOne((type) => User, (user) => user.articls)
  user: User;

  @ManyToMany((type) => User, (user) => user.collectArticles)
  @Exclude()
  collectUsers: User[];

  @ManyToMany((type) => Tags, (tags) => tags.articles, {
    cascade: true,
  })
  @JoinTable()
  tags: Tags[];
}
